#filter-out是将 src/main.cpp 排除掉
libs_srcs := $(filter-out src/main.cpp,$(shell find src -name *.cpp))
libs_objs := $(patsubst src/%.cpp,objs/%.o,$(libs_srcs))

include_paths := ./include

library_paths := ./lib

linking_libs  := xxx

I_options := $(include_paths:%=-I%)
l_options := $(linking_libs:%=-l%)
L_options := $(library_paths:%=-L%)

#compile : 编译的意思 编译选项
compile_flags := -g -O3 -std=c++11 $(I_options)
linking_flags := $(l_options) $(L_options)

# ========== 编译静态库 ==========
objs/%.o : src/%.cpp
	@mkdir -p $(dir $@)
	@g++ -c $^ -o $@ $(compile_flags)

lib/libxxx.a : $(libs_objs)
	@mkdir -p $(dir $@)
	@ar -r $@ $^

static_lib : lib/libxxx.a

# ========== 链接静态库 ==========

objs/main.o : src/main.cpp
	@mkdir -p $(dir $@)
	@g++ -c $^ -o $@ $(compile_flags)

workspace/exec : objs/main.o
	@mkdir -p $(dir $@)
	@g++ $^ -o $@ $(linking_flags)

run : workspace/exec

	@./$<

debug :

	@echo $(libs_srcs)
	@echo $(libs_objs)

clean:
	rm -rf objs lib workspace

.PHONY:debug clean run static_lib 

